package com.xfp.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xfp.mapper.VmTypeMapper;
import com.xfp.method.pageTotal;
import com.xfp.pojo.dto.VmTypePageDto;
import com.xfp.pojo.dto.newVmTypeDto;
import com.xfp.pojo.entity.VmType;
import com.xfp.pojo.vo.VmTypePageVo;
import com.xfp.pojo.vo.VmTypeVo;
import com.xfp.service.VmTypeSrevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class VmTypeImp implements VmTypeSrevice {

    @Autowired
    private VmTypeMapper vmTypeMapper;

    /**
     * 查询设备类型
     * @param dto
     */
    @Override
    public VmTypePageVo queryVmType(VmTypePageDto dto) {
        //使用分页插件
        PageHelper.startPage(dto.getPageIndex(),dto.getPageSize());
        Page<VmType> page = vmTypeMapper.queryVmType(dto);
        //计算总页数
        Long l = pageTotal.total(page.getTotal(),dto.getPageSize());
        VmTypePageVo vo = VmTypePageVo.builder()
                .pageIndex(dto.getPageIndex())
                .pageSize(dto.getPageSize())
                .totalPage(l)
                .totalCount(page.getTotal())
                .currentPageRecords(page.getResult())
                .build();
        return vo;
    }

    /**
     * 新增设备类型
     * @param dto
     */
    @Override
    public void insertVmType(newVmTypeDto dto) {
        vmTypeMapper.insertVmType(dto);
    }

    /**
     * 修改设备类型
     * @param typeId
     * @param dto
     */
    @Override
    public void updateVmType(Long typeId, newVmTypeDto dto) {
        vmTypeMapper.updateVmType(dto,typeId);
    }

    /**
     * 删除售货机类型
     * @param typeId
     */
    @Override
    public void deleteType(Long typeId) {
        vmTypeMapper.deleteVmType(typeId);
    }

    /**
     * 售货机类型详情
     * @param typeId
     * @return
     */
    @Override
    public VmTypeVo findType(Integer typeId) {
        VmTypeVo vo = vmTypeMapper.findType(typeId);
        return vo;
    }
}
